﻿using ManagementToolClient.BaseViewModels;
using ManagementToolClient.PageDeclaration;
using Newtonsoft.Json;
using Prism.Commands;
using Prism.Ioc;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ManagementToolClient.ViewModels
{
    public class MainWindowViewModel : ViewBindModelBase
    {

        #region cmd
        private DelegateCommand _CloseCommand;
        public DelegateCommand CloseCommand =>
            _CloseCommand ?? (_CloseCommand = new DelegateCommand(CloseCommandMethod));

        private DelegateCommand _MaxCommand;
        public DelegateCommand MaxCommand =>
            _MaxCommand ?? (_MaxCommand = new DelegateCommand(MaxCommandMethod));

        private DelegateCommand _MinCommand;
        public DelegateCommand MinCommand =>
            _MinCommand ?? (_MinCommand = new DelegateCommand(MinCommandMethod));


        private DelegateCommand _CompanyControlnCommand;
        public DelegateCommand CompanyControlnCommand =>
            _CompanyControlnCommand ?? (_CompanyControlnCommand = new DelegateCommand(ExcuteCompanyControlnCommand));

    
        private DelegateCommand _DeviceControlnCommand;
        public DelegateCommand DeviceControlnCommand =>
            _DeviceControlnCommand ?? (_DeviceControlnCommand = new DelegateCommand(ExcuteDeviceControlnCommand));


        private DelegateCommand _ModuleControlnCommand;
        public DelegateCommand ModuleControlnCommand =>
            _ModuleControlnCommand ?? (_ModuleControlnCommand = new DelegateCommand(ExcuteModuleControlnCommand));

    



        #endregion

        public MainWindowViewModel(IContainerExtension container) : base(container)
        {

        }

        public override  void ExecuteLoadedCommand()
        {
            base.ExecuteLoadedCommand();
            ToTargetConfigPage(SystemResourceExten.Nav_CompanyManagerPageView);
        }



        public override void ExecuteUnLoadedCommand()
        {
            base.ExecuteUnLoadedCommand();
        }


        private void ExcuteCompanyControlnCommand()
        {
            NavigationParameters itemParameter = new NavigationParameters();
            Application.Current?.Dispatcher.Invoke(() => {
                Region.RequestNavigate(SystemResourceExten.Nav_MainContent, SystemResourceExten.Nav_CompanyManagerPageView, itemParameter);
            });
        }

        private void ExcuteDeviceControlnCommand()
        {
            NavigationParameters itemParameter = new NavigationParameters();
            Application.Current?.Dispatcher.Invoke(() => {
                Region.RequestNavigate(SystemResourceExten.Nav_MainContent, SystemResourceExten.Nav_DeviceManagerView, itemParameter);
            });
        }
        private void ExcuteModuleControlnCommand()
        {

        }

        private void ToTargetConfigPage(string _PagName)
        {
            NavigationParameters itemParameter = new NavigationParameters();
            Application.Current?.Dispatcher.Invoke(() => {
                Region.RequestNavigate(SystemResourceExten.Nav_MainContent, _PagName, itemParameter);
            });
        }
      
        private void MinCommandMethod()
        {
            Application.Current.MainWindow.WindowState = WindowState.Minimized;

        }

        private void MaxCommandMethod()
        {
            Application.Current.MainWindow.WindowState = Application.Current.MainWindow.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
        }

        private  void CloseCommandMethod()
        {
            CommonStaticModel.IsQuiteApp = true;

            Application.Current.Shutdown();
            Console.WriteLine("退出软件");
        }

    }
}
